<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>招投标管理系统</title>
    <style>
        html,body {
            background-image: url();
        }
        body {
            background-color: #f4f4f4;
            font-family: Arial, sans-serif;
        }
        
        .header {
            background-color: #333;
            color: #fff;
            padding: 20px;
            text-align: center;
        }
        .container {
            max-width: 300px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            border-radius: 5px;
            margin-top: 100px;
        }

        h2 {
            text-align: center;
            margin-bottom: 20px;
        }

        label {
            font-weight: bold;
        }

        input[type="text"],
        input[type="password"] {
            width: 90%;
            padding: 10px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        input[type="submit"] {
            background-color: #4CAF50;
            color: #fff;
            padding: 10px;
            border: none;
            cursor: pointer;
            width: 100%;
            border-radius: 4px;
        }

        input[type="submit"]:hover {
            background-color: #45a049;
        }
        
    </style>
</head>
<body>
    <div class="header">
        <h1>招投标管理系统</h1>
    </div>

    <div class="container">
        <h2>登入</h2>
        <label for="username">用户名:</label>
        <input type="text" id="username" placeholder="请输入用户名">
        <label for="password">密码:</label>
        <input type="password" id="password" placeholder="请输入密码">
        <input type="submit" id="submit" value="登入">
        <div class="link">还没有账号？<a href="register.html">注册</a></div>
    </div>


    <script src="./js/jquery.min.js"></script>
    <script>
        // 获取用户名和密码
        let submitButton = document.querySelector('#submit');
        // 进行登录验证
        submitButton.onclick = function(){
            var username = $('#username').val();
            var password = $('#password').val();
            //发送Ajax请求
            $.ajax({
                method:'post',
                url:'/login',
                data:{
                    name:username,
                    password:password
                },
                success:function(data){
                    console.log(JSON.stringify(data));
                    if(data && data.id > 0){
                        alert("登入成功");
                        if(data.groupName == "admin"){
                            location.replace("/admin.html");
                        }else if(data.groupName == "招标单位"){
                            location.replace("/tendering_unit.html");
                        }else{
                            location.replace("/manufacturer.html");
                        }
                    } else{
                        alert("登入失败！");
                    }
                }
            })
        }
    </script>
</body>
</html>